<template>
    <el-checkbox-group v-model="checkList" @change="updataCheckboxChange">
        <el-checkbox label="apply">申请</el-checkbox>
        <el-checkbox label="report">报表</el-checkbox>
    </el-checkbox-group>
</template>
<script>
import { updateUserInfo } from "../../../components/axios/url";
import http from "../../../components/axios/fetch";

    export default {
        name: "cost-center-select",
        data(){
            return{
                checkList: []
            }
        },
        props: {
            scope: {},
        },
        mounted() {
            this.updataCheckList();
        },
        methods: {
            updataCheckboxChange(checked) {
                let apply = checked.length === 0 ? 1 : 1;
                let report = checked.length === 0 ? 1 : 1;

                if(checked.length !== 0) {
                    checked.forEach((item) => {
                        if(item === 'apply') {
                            apply = 2;
                        }
                        if(item === 'report') {
                            report = 2;
                        }
                    })
                }
                const param = {
                    userId: this.scope.row.userId,
                    apply: apply,
                    report: report,
                };
                try{
                    http.post(updateUserInfo, param).then(res => {
                        if(res.data && res.data.resultMess === "success") {
                            this.$notify({
                                title: '提示',
                                message: '修改成功',
                                type: 'success'
                            });
                        }
                    })
                }catch(error){
                    this.$notify.error({
                        title: '提示',
                        message: '网络错误',
                    });
                }
            },
            updataCheckList() {
                if(this.scope.row.apply === 2) this.checkList.push('apply');
                if(this.scope.row.report === 2) this.checkList.push('report');
            }

        }
    }
</script>

<style scoped>

</style>
